<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-07-07 15:57:01
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" 
-->
<template>
  <el-container style="height: 100%">
    <el-main style="height: 100%">
      <sc-VxeTable
        ref="xGrid1"
        :gridEvts="gridEvents"
        :tablecode="'basedata_point_stick'"
        :url="this.$API.basedata.PointStick.list"
      >
      </sc-VxeTable>
    </el-main>
    <save-dialog
      v-if="dialog.save"
      ref="saveDialog"
      @success="handleSuccess"
      @closed="dialog.save = false"
    >
    </save-dialog>
  </el-container>
</template>
<script>
// import { useRouter } from "vue-router";
// import { VXETable } from 'vxe-table';
import { ElNotification } from "element-plus";

import SaveDialog from "./save";
export default {
  components: {
    SaveDialog,
  },
  name: "Point_stick",
  data() {
    return {
      dialog: {
        save: false,
      },
      gridEvents: {
        cellDblclick: ({ row }) => {
          this.edit(row);
        },
        add: () => {
          this.add();
        },
        edit: () => {
          this.edit();
        },
        del: () => {
          this.del();
        },
      },
    };
  },
  methods: {
    add: function () {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open();
      });
    },
    handleSuccess() {
      this.$refs.xGrid1.refresh();
    },
    edit(item) {
      let selected = {};
      if (typeof item == "undefined") {
        let selects = this.$refs.xGrid1.xGrid.getCheckboxRecords();
        if (selects.length == 0) {
          this.$message.error("必须选中元素");
          return;
        } else {
          selected = selects[0];
        }
      } else selected = item;
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(selected);
      });
    },
    async del() {
      let selected = this.$refs.xGrid1.xGrid.getCheckboxRecords();
      if (selected.length == 0) {
        ElNotification.error({
          title: "错误",
          message: "必须选中元素",
        });
        return;
      }
      let ids = [];
      selected.forEach((element) => {
        ids.push(element.id);
      });
      var res = await this.$API.basedata.loom.delete.post({ ids: ids });
      this.isSaveing = false;
      if (res.code == 200) {
        this.$emit("success", this.form, this.mode);
        this.visible = false;
        this.$refs.xGrid1.refresh();
        this.$message.success("操作成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
  },
};
</script>
